package com.example.basic.web.controller.parameter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.parameter.Parameter;
import com.example.basic.web.service.parameter.ParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 全局参数表 前端控制器
 * </p>
 *
 * @author zhangzq
 * @since 2023-12-08
 */
@Api(value = "全局参数表相关操作", tags = {"全局参数表"})
@RestController
@RequestMapping("/api/v1/byg/parameter")
public class ParameterController {
    @Resource
    private ParameterService parameterService;

    /**
     * 新增或修改 zq
     * @param parameter 参数实体
     * @return
     */
    @Log(title = "全局参数表", description = "新增或修改")
    @ApiOperation("新增或修改")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Parameter parameter) {
        return ResultGenerator.genSuccessResult(parameterService.saveOrUpdate(parameter));
    }

    /**
     * 删除 zq
     * @param id 唯一id
     * @param request
     * @return
     */
    @Log(title = "全局参数表", description = "删除")
    @ApiOperation(value="删除",notes = "删除")
    @PostMapping("/delete")
    public Result delete(@ApiParam(value = "唯一id",name = "id") @RequestParam String id,
                                 HttpServletRequest request) {
            return ResultGenerator.genSuccessResult(parameterService.delete(id));
    }

    /**
     * 根据参数名查询参数值 zq
     * @param paramName 参数名
     * @return
     */
    @Log(title = "全局参数表", description = "根据参数名查询参数值")
    @ApiOperation(value = "根据参数名查询参数值", notes = "根据参数名查询参数值")
    @PostMapping("/getTransValueByName")
    public Result getTransValueByName(
            @ApiParam(value = "参数名", name = "paramName") @RequestParam String paramName) {
        return ResultGenerator.genSuccessResult(parameterService.getTransValueByName(paramName));
    }

    /**
     * 列表(分页,没有筛选条件) zq
     * @param page
     * @param size
     * @param searchParam 模糊搜索
     * @param request
     * @return
     */
    @Log(title = "全局参数表", description = "列表")
    @ApiOperation(value="列表(分页,没有筛选条件)",notes = "列表(分页,没有筛选条件)")
    @PostMapping("/queryList")
    public Result queryList(@ApiParam(value = "页码",name = "page") @RequestParam(defaultValue = "0") Integer page,
                                    @ApiParam(value = "数量",name = "size") @RequestParam(defaultValue = "0")  Integer size,
                                    @ApiParam(value = "模糊搜索",name = "searchParam") @RequestParam(defaultValue = "")  String searchParam,
                                    HttpServletRequest request) {
        Page<Parameter> queryPage  = new Page<Parameter>(page,size);
        IPage<Parameter> list = parameterService.queryList(queryPage,searchParam);
        return ResultGenerator.genSuccessResult(list);
    }
}
